package com.mac.intellect_flow.flowable.config;

import com.mac.intellect_flow.flowable.listener.GlobalEventListener;
import lombok.AllArgsConstructor;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.engine.RuntimeService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;

/**
 * flowable全局监听配置
 *
 * @author mac
 */
@Configuration
@AllArgsConstructor
public class GlobalEventListenerConfig implements ApplicationRunner {

	private final GlobalEventListener globalEventListener;
	private final RuntimeService runtimeService;

	@Override
	public void run(ApplicationArguments args) throws Exception {
		// 流程结束
		runtimeService.addEventListener(globalEventListener, FlowableEngineEventType.PROCESS_COMPLETED);
	}
}
